/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SuratJalanDetailForm.java
 *
 * Created on Jul 25, 2010, 5:50:02 PM
 */
package com.oi.eksekutif.ui.detail;

import com.oi.eksekutif.dao.MobilDAO;
import com.oi.eksekutif.dao.PengemudiDAO;
import com.oi.eksekutif.dao.SuratJalanDAO;
import com.oi.eksekutif.domain.Mobil;
import com.oi.eksekutif.domain.Pengemudi;
import com.oi.eksekutif.domain.SuratJalan;
import java.util.Calendar;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Pussy
 */
public class SuratJalanDetailForm extends javax.swing.JPanel {

    private static final org.slf4j.Logger log = LoggerFactory.getLogger(SuratJalanDetailForm.class);
    private SuratJalanDAO suratJalanDAO;
    private SuratJalan suratJalan;
    private PengemudiDAO pengemudiDAO;
    private MobilDAO mobilDAO;
    private Pengemudi pengemudi;
    private boolean enabled;
    private Mobil mobil;
    private Long noPintu, noKPP;

    public MobilDAO getMobilDAO() {
        return mobilDAO;
    }

    public void setMobilDAO(MobilDAO mobilDAO) {
        this.mobilDAO = mobilDAO;

    }

    public PengemudiDAO getPengemudiDAO() {
        return pengemudiDAO;
    }

    public void setPengemudiDAO(PengemudiDAO pengemudiDAO) {
        this.pengemudiDAO = pengemudiDAO;
    }

    /** Creates new form SuratJalanDetailForm */
    public SuratJalanDetailForm() {
        initComponents();
    }

    public SuratJalan getSuratJalan() {

        this.suratJalan.setMobil(this.mobil);
        this.suratJalan.setPengemudi(this.pengemudi);
        Calendar cal = Calendar.getInstance();
        cal.setTime(this.tanggalKeberangkatanDateChooser.getDate());
        cal.set(Calendar.HOUR_OF_DAY, (Integer) jamSpinner.getValue());
        cal.set(Calendar.MINUTE, (Integer) menitSpinner.getValue());
        this.suratJalan.setTanggalKeberangkatan(cal.getTime());
        return suratJalan;
    }

    public void setSuratJalan(SuratJalan suratJalan) {
        this.suratJalan = suratJalan;
        this.mobilTextField.setText(this.suratJalan.getMobil().getNomorPintu());
        this.nomorPolisiTextField.setText(this.suratJalan.getMobil().getNomorPolisi());
        this.merkTextField.setText(this.suratJalan.getMobil().getMerkMobil().toString());
        this.nomorKppTextField.setText(this.suratJalan.getPengemudi().getNomorKpp());
        this.namaTextField.setText(this.suratJalan.getPengemudi().getNama());
        this.posisiTextField.setText(this.suratJalan.getPengemudi().getPosisi().getNama());
        this.tanggalKeberangkatanDateChooser.setDate(this.suratJalan.getTanggalKeberangkatan());
        Calendar cal = Calendar.getInstance();
        cal.setTime(this.suratJalan.getTanggalKeberangkatan());

        this.jamSpinner.setValue(cal.get(Calendar.HOUR_OF_DAY));
        this.menitSpinner.setValue(cal.get(Calendar.MINUTE));

    }

    @Override
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
        this.nomorKppTextField.setEditable(enabled);
        this.mobilTextField.setEditable(enabled);
        this.tanggalKeberangkatanDateChooser.setEnabled(enabled);
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField5 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        mobilTextField = new javax.swing.JTextField();
        mobilCariButton = new javax.swing.JButton();
        nomorKppTextField = new javax.swing.JTextField();
        pengemudiCariButton = new javax.swing.JButton();
        tanggalKeberangkatanDateChooser = new com.toedter.calendar.JDateChooser();
        nomorPolisiTextField = new javax.swing.JTextField();
        merkTextField = new javax.swing.JTextField();
        namaTextField = new javax.swing.JTextField();
        posisiTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jamSpinner = new javax.swing.JSpinner();
        menitSpinner = new javax.swing.JSpinner();
        jLabel9 = new javax.swing.JLabel();

        jTextField5.setText("jTextField5");

        setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel1.setText("Nomor Pintu :");

        jLabel2.setText("Nomor KPP :");

        jLabel3.setText("Tanggal Keberangkatan :");

        mobilCariButton.setText("Cari");
        mobilCariButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mobilCariButtonActionPerformed(evt);
            }
        });

        pengemudiCariButton.setText("Cari");
        pengemudiCariButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pengemudiCariButtonActionPerformed(evt);
            }
        });

        tanggalKeberangkatanDateChooser.setDateFormatString("dd MMMM yyyy");

        nomorPolisiTextField.setEditable(false);

        merkTextField.setEditable(false);

        namaTextField.setEditable(false);

        posisiTextField.setEditable(false);

        jLabel4.setText("Nomor Polisi :");

        jLabel5.setText("Merk :");

        jLabel6.setText("Nama :");

        jLabel7.setText("Posisi :");

        jLabel8.setText("Jam Keberangkatan :");

        jamSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 23, 1));

        menitSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 59, 1));

        jLabel9.setText(":");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel3)
                    .addComponent(jLabel7)
                    .addComponent(jLabel6)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tanggalKeberangkatanDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(posisiTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                            .addComponent(namaTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                            .addComponent(nomorKppTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                            .addComponent(mobilTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                            .addComponent(nomorPolisiTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
                            .addComponent(merkTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(pengemudiCariButton, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE)
                            .addComponent(mobilCariButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jamSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(7, 7, 7)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(menitSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mobilTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mobilCariButton)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomorPolisiTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(merkTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomorKppTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pengemudiCariButton)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(namaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(posisiTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tanggalKeberangkatanDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jamSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(menitSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void mobilCariButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mobilCariButtonActionPerformed
        // TODO add your handling code here:
        try {
            mobil = mobilDAO.findByNomorPintu(this.mobilTextField.getText());
            this.nomorPolisiTextField.setText(mobil.getNomorPolisi());
            this.merkTextField.setText(mobil.getMerkMobil().toString());
        } catch (Exception e) {
            log.warn("Data Tidak Ketemu "+e.getMessage());
        }

    }//GEN-LAST:event_mobilCariButtonActionPerformed

    private void pengemudiCariButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pengemudiCariButtonActionPerformed
        // TODO add your handling code here:
        try {
            pengemudi = pengemudiDAO.findByNomorKPP(this.nomorKppTextField.getText());
            this.namaTextField.setText(pengemudi.getNama());
            this.posisiTextField.setText(this.pengemudi.getPosisi().getNama());
        } catch (Exception e) {
            log.warn("Data Tidak Ketemu "+e.getMessage());
        }
    }//GEN-LAST:event_pengemudiCariButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JSpinner jamSpinner;
    private javax.swing.JSpinner menitSpinner;
    private javax.swing.JTextField merkTextField;
    private javax.swing.JButton mobilCariButton;
    private javax.swing.JTextField mobilTextField;
    private javax.swing.JTextField namaTextField;
    private javax.swing.JTextField nomorKppTextField;
    private javax.swing.JTextField nomorPolisiTextField;
    private javax.swing.JButton pengemudiCariButton;
    private javax.swing.JTextField posisiTextField;
    private com.toedter.calendar.JDateChooser tanggalKeberangkatanDateChooser;
    // End of variables declaration//GEN-END:variables
}
